package com.wpi.smarttour.helpers;
import android.location.GpsStatus;
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;
import com.wpi.smarttour.MapActivity;
import com.wpi.smarttour.SmartRecording;
import com.wpi.smarttour.SmartTour;

/*
 * GPS Listener
 * This sends data to other activities
 */
public class LocationListenerHelper implements LocationListener, GpsStatus.Listener
{
   static MapActivity mapActivity;
   static SmartRecording recordingActivity;

   public LocationListenerHelper(MapActivity activity)
   {
      mapActivity = activity;
   }

   public LocationListenerHelper(SmartRecording activity)
   {
      recordingActivity = activity;
   }

   /**
    * Event raised when a new fix is received.
    */
   public void onLocationChanged(Location loc)
   {
      Utilities.LogInfo("Location changed");
      try
      {
         // MapActivity.currentLatitude = loc.getLatitude();
         // MapActivity.currentLongitude = loc.getLongitude();
         if (SmartTour.isMapRunning == true)
         {
            if (loc != null)
            {
               mapActivity.updateWithNewLocation(loc);
            }
         }
         else if (SmartTour.isRecordRunning == true)
         {
            if (SmartRecording.isRecording == false)
            {
               recordingActivity.displayNewLocation(loc);
            }
            else
            {
               if (loc != null)
               {
                  recordingActivity.updateWithNewLocation(loc);
               }
            }
         }
      }
      catch (Exception ex)
      {
         Utilities.LogError("listener", ex);
      }
   }

   public void onProviderDisabled(String provider)
   {
      Utilities.LogInfo("Provider disabled");
      // mainActivity.RestartGpsManagers();
      /* this is called if/when the GPS is disabled in settings */
      /* bring up the GPS settings */
      // Intent intent = new Intent(
      // android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
      // startActivity(intent);
   }

   public void onProviderEnabled(String provider)
   {
      Utilities.LogInfo("Provider enabled");
      // mainActivity.RestartGpsManagers();
   }

   public void onStatusChanged(String provider, int status, Bundle extras)
   {
      Utilities.LogInfo("Status changed");
   }

   public void onGpsStatusChanged(int event)
   {
      Utilities.LogInfo("GPS Status changed");
   }
}